module.exports = options => {
  return async function jwt(ctx:any, next:any) {
    const token = ctx.request.header.authorization;
    if (token) {
      try {
        // 解密token
        ctx.app.jwt.verify(token, options.secret);
        await next();
      } catch (error:any) {
        ctx.body = {
          code: 2,
          message: error.message,
          result: [],
        };
        return;
      }
    } else {
      ctx.body = {
        code: 2,
        message: 'token失效,请重新登录',
        result: [],
      };
      return;
    }
  };
};
